package com.example.boot2mybatis.controller;


import com.example.boot2mybatis.pubsub.EventPublisher;
import com.example.boot2mybatis.pubsub.LoginSuccessEvent;
import com.example.boot2mybatis.pubsub.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class LoginController {

    @Autowired
    EventPublisher eventPublisher;

    @GetMapping("/login")
    public String login(@RequestParam("uname") String uname,
                        @RequestParam("passwd") String passwd) {
        // 业务处理登录
        System.out.println("=====业务处理登录完成======");

        // 如果是分布式服务，可以发布分布式事件
        LoginSuccessEvent event = new LoginSuccessEvent(new UserEntity(uname, passwd));
        eventPublisher.sendEvent(event);

        return uname + "登录成功";
    }
}

